package com.bix.util.blizfiles.dds;

import java.nio.ByteBuffer;


class DDSAlphaBlockExplicit {
	private	short		row[] = new short[4];
	
	public DDSAlphaBlockExplicit () {
	}
	
	public DDSAlphaBlockExplicit (ByteBuffer bb) {
		for (int i = 0; i < row.length; i++) {
			row[i] = bb.getShort();
		}
	}

	public DDSAlphaBlockExplicit (short[] row) {
		this.row = row;
	}
	
	public void setRow (short[] row) {
		this.row = row;
	}
	
	public short[] getRow () {
		return this.row;
	}
	
	/**
	 * This method decodes a DDS explicit alpha block of data.
	 * 
	 * @param destination
	 * @param offset
	 * @param width
	 * @param alphaZero
	 */
	public void decode (int[] destination, int offset, int width, int alphaZero) {	
		DDSColorAlpha	clearColor = new DDSColorAlpha (new DDSColor (0,0,0), 0);
		
		for (int row = 0; row < 4; row++, offset += width ) {
			long word = this.getRow()[row];
			for (int pix = offset; pix < offset + 4; pix++, word >>=4 ) {
				destination[pix] &= alphaZero;
				clearColor.setAlpha((byte)(((word & 0xF) << 4) | (word & 0xF)));
				destination[pix] |= clearColor.getAsInteger();
			}
		}
	}
}